//
//  JHPicTableViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-14.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHPicTableViewCell.h"
#import "NetwordHandler.h"
#import "UIImageView+WebCache.h"
#import "JHCharacterViewController.h"

@implementation JHPicTableViewCell
- (void)dealloc
{
    [_balckimage release];
    [_myimage1 release];
    [_myLabel7 release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.balckimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2870A99B-2C04-4DBF-A15F-66FBC07AD341"]];

        [self.contentView addSubview:_balckimage];
        
        self.myLabel7 = [[UILabel alloc] init];
        self.myLabel7.numberOfLines = 0;
//        self.myLabel7.backgroundColor = [UIColor greenColor];
        [self.myLabel7 sizeToFit];
        self.myLabel7.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:self.myLabel7];
        [_myLabel7 release];
        
//        [self picFromWeb];
        
        self.myimage1 = [[UIImageView alloc] init];
        [self.balckimage addSubview:_myimage1];
        _myimage1.backgroundColor = [UIColor blueColor];
//        _myimage1.contentMode = UIViewContentModeScaleAspectFit;

    }
    return self;
}


+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(330, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _balckimage.frame = CGRectMake(5, 10, self.contentView.frame.size.width - 10, self.contentView.frame.size.height - 15);
    
    CGFloat f1 = [[self class] heightWithText:_myLabel7.text];
//    NSLog(@"++++++++%@", _myLabel7.text);
    _myLabel7.frame = CGRectMake(20, 25, self.balckimage.frame.size.width - 30, f1);
    _myimage1.frame = CGRectMake(15, self.myLabel7.frame.size.height + 20, _w, _h);

}

- (void)setObjc:(JHCharacterObject *)objc
{
    if (objc != _objc) {
        [_objc release];
        _objc = [objc retain];
    }
    
    _myLabel7.text = objc.text;
    
    CGFloat biLi =  [objc.height floatValue] / [objc.width floatValue] ;
    NSLog(@"++++++++++width = %@", objc.width);
    NSLog(@"----------height = %@", objc.height);
    NSLog(@"%lf", biLi);
    _w = _balckimage.frame.size.width - 30;
    _h = (_balckimage.frame.size.width - 30) * biLi;
//    _myimage1.frame = CGRectMake(15, self.myLabel7.frame.size.height + 30, _w, _h);
    [_myimage1 sd_setImageWithURL:[NSURL URLWithString:objc.image0] placeholderImage:[UIImage imageNamed:@"iconfont-tupian"]];

    
//    NSLog(@"+++++++++++++%lf")
    NSLog(@"---------------%lf", (_balckimage.frame.size.width - 30) * biLi);


}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    

    // Configure the view for the selected state
}

@end
